package bairui.international.console.web.controller.branch.branch.staff;

/**
 *
 * ExcelOutput_ExcelExport_Output_Detail
 * excel输出
 */
class ExcelOutput_ExcelExport_Output_Detail

{

	/**
	 * 创建sheet
	 */
	public static com.sh_lianjing.file.excel.write.ExcelWriter createSheet(
		String sheetName,
		java.util.List<Model> list
	) throws Exception{
		return createSheet(sheetName, com.sh_lianjing.file.excel.write.ExcelWriter.newInstanceExcel2007BigData(), list);
	}
	
	public static com.sh_lianjing.file.excel.write.ExcelWriter createSheet(
		String sheetName,
		com.sh_lianjing.file.excel.write.ExcelWriter writer,
		java.util.List<Model> list
	) throws Exception{
		return createSheet(sheetName, writer, Model.class, list, null);
	}

	public static <E extends Model, D> com.sh_lianjing.file.excel.write.ExcelWriter createSheet(
		String sheetName,
		com.sh_lianjing.file.excel.write.ExcelWriter writer,
		Class<E> type,
		java.util.List<E> list,
		D headCommentsData
	) throws Exception{
		return writer
				.createSheet(
					sheetName, 
					type,
					list,
					headCommentsData
				);
	}

	/**
	 * 输出文件
	 */
	public static void output(
		java.util.List<Model> list,
		javax.servlet.http.HttpServletRequest request,
		javax.servlet.http.HttpServletResponse response
	) throws Exception{
		output(
			"分公司员工", 
			createSheet("分公司员工", list), 
			request, 
			response
		);
	}

	public static void output(
		String fileName,
		com.sh_lianjing.file.excel.write.ExcelWriter writer,
		javax.servlet.http.HttpServletRequest request,
		javax.servlet.http.HttpServletResponse response
	) throws Exception{
		// 设置格式
		com.lianjing.sh.web.common.util.Util_Web.setDownloadFileName(request, response, fileName+".xlsx");
		response.setContentType(org.springframework.http.MediaType.APPLICATION_XML_VALUE);
		// 生成excel并输出
		try{
			writer.writeTo(response.getOutputStream());
		} finally {
			writer.close();
		};
	}

	
	/**
	 * 排序扩展接口
	 */
	static interface OrderExtends {
		org.springframework.data.domain.Sort gainNickName(
			org.springframework.data.domain.Sort.Direction direction
		);
		org.springframework.data.domain.Sort gainRealName(
			org.springframework.data.domain.Sort.Direction direction
		);
		org.springframework.data.domain.Sort gainPhone(
			org.springframework.data.domain.Sort.Direction direction
		);
		org.springframework.data.domain.Sort gainCreateTime(
			org.springframework.data.domain.Sort.Direction direction
		);
		org.springframework.data.domain.Sort gainState(
			org.springframework.data.domain.Sort.Direction direction
		);
		
	
		default org.springframework.data.domain.Sort sort(
			org.springframework.data.domain.Sort.Direction direction,
			com.querydsl.core.types.dsl.ComparableExpressionBase<?> ... sortBase
		){
			return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.sortTrans(direction, sortBase);
		}
	
		default com.querydsl.core.types.OrderSpecifier<?> order(
			org.springframework.data.domain.Sort.Direction direction,
			com.querydsl.core.types.dsl.ComparableExpressionBase<?> orderBase
		){
			return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.orderTrans(direction, orderBase);
		}
	}
	
	/**
	 * 排序
	 */
	final static org.springframework.data.domain.Sort sort(
		bairui.international.model.domain.jpa.QTB_BranchCompanyStaff QRoot,
		javax.servlet.http.HttpServletRequest request
		,OrderExtends orderExtends
	){
		/*
		 * 排序属性
		 */
		// orderBy @RequestParam(name="orderBy", required=false, defaultValue="orderValue") String orderBy
		String orderByPara = request.getParameter(com.lianjing.sh.web.separatepage.OrderInfo.OrderBy);
		if(null == orderByPara){
			orderByPara = "id";
		}
		// orderWay @RequestParam(name="orderWay", required=false, defaultValue="DESC") OrderWay orderWay
		String orderWayPara = request.getParameter(com.lianjing.sh.web.separatepage.OrderInfo.OrderWay);
		if(null == orderWayPara){
			orderWayPara = "DESC";
		}
		org.springframework.data.domain.Sort.Direction direction = org.springframework.data.domain.Sort.Direction.valueOf(orderWayPara);
	
		//
		switch(orderByPara){
			case "nickName":		return orderExtends.gainNickName(direction);
			case "realName":		return orderExtends.gainRealName(direction);
			case "phone":		return orderExtends.gainPhone(direction);
			case "directorFlag":		return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.sortTrans(direction, QRoot.directorFlag);
			case "createTime":		return orderExtends.gainCreateTime(direction);
			case "state":		return orderExtends.gainState(direction);
			case "id":	return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.sortTrans(direction, QRoot.id);
			default:
				throw new RuntimeException();
		}
	}
	

	@com.sh_lianjing.file.excel.write.annotation.WriteExcel
	@SuppressWarnings(value="serial")
	abstract 
	public static class Model extends bairui.international.model.domain.jpa.TB_BranchCompanyStaff{
	
		/**
		 * 构造函数
		 */
		@lombok.Getter @com.fasterxml.jackson.annotation.JsonIgnore
		private bairui.international.model.domain.jpa.TB_BranchCompanyStaff _origin;
	
		public Model(
			bairui.international.model.domain.jpa.TB_BranchCompanyStaff bean
		) {
			this._origin = bean;
			if(null != bean){
				this.setId(bean.getId());
				this.setDirectorFlag(bean.getDirectorFlag());
			}
			/* 附加属性赋值前 */
			assign_before();
			/* 附加属性赋值 */
			this.setNickName(this.assignNickName());
			this.setRealName(this.assignRealName());
			this.setPhone(this.assignPhone());
			this.setCreateTime(this.assignCreateTime());
			this.setState(this.assignState());
		}
		
		
		@com.sh_lianjing.reflect.method.annotation.MethodOrder(2)
		@com.sh_lianjing.file.excel.write.annotation.WriteExcelCell(comment = "昵称")
		/** get[昵称] */
		public String getNickName() {
			return this.nickName;
		}
		
		@com.sh_lianjing.reflect.method.annotation.MethodOrder(3)
		@com.sh_lianjing.file.excel.write.annotation.WriteExcelCell(comment = "真实姓名")
		/** get[真实姓名] */
		public String getRealName() {
			return this.realName;
		}
		
		@com.sh_lianjing.reflect.method.annotation.MethodOrder(4)
		@com.sh_lianjing.file.excel.write.annotation.WriteExcelCell(comment = "电话")
		/** get[电话] */
		public String getPhone() {
			return this.phone;
		}
		
		@com.sh_lianjing.reflect.method.annotation.MethodOrder(5)
		@com.sh_lianjing.file.excel.write.annotation.WriteExcelCell(comment = "是否为负责人")
		
		@Override
		public Boolean getDirectorFlag() {
			return (Boolean)super.getDirectorFlag();
		}
		
		@com.sh_lianjing.reflect.method.annotation.MethodOrder(6)
		@com.sh_lianjing.file.excel.write.annotation.WriteExcelDateFormat(pattern = "yyyy-MM-dd")
		@com.sh_lianjing.file.excel.write.annotation.WriteExcelCell(comment = "注册时间")
		/** get[注册时间] */
		public java.util.Date getCreateTime() {
			return this.createTime;
		}
		
		@com.sh_lianjing.reflect.method.annotation.MethodOrder(7)
		@com.sh_lianjing.file.excel.write.annotation.WriteExcelCell(comment = "状态")
		/** get[状态] */
		public bairui.international.model.status.State_User getState() {
			return this.state;
		}
		
		
		/**
		 * 非继承属性
		 */
		abstract protected void assign_before();
		
		/** 昵称 */
		 @lombok.Setter 
		private String nickName;
		/** 赋值昵称 */
		abstract protected String assignNickName();
	
		/** 真实姓名 */
		 @lombok.Setter 
		private String realName;
		/** 赋值真实姓名 */
		abstract protected String assignRealName();
	
		/** 电话 */
		 @lombok.Setter 
		private String phone;
		/** 赋值电话 */
		abstract protected String assignPhone();
	
		/** 注册时间 */
		 @lombok.Setter 
		private java.util.Date createTime;
		/** 赋值注册时间 */
		abstract protected java.util.Date assignCreateTime();
	
		/** 状态 */
		 @lombok.Setter 
		private bairui.international.model.status.State_User state;
		/** 赋值状态 */
		abstract protected bairui.international.model.status.State_User assignState();
	
		/**
		 * 相关类
		 */
	}
	

}

